package com.example.lenovo.demo.presenter.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.lenovo.demo.R;
import com.example.lenovo.demo.model.databean.TravelsBean;

import java.util.List;

/**
 * Created by Administrator on 2017/1/10.
 */

public class Travles_ImgRvAdapter extends RecyclerView.Adapter<Travles_ImgRvAdapter.ViewHolder> {
    private List<TravelsBean.DataBean.ActivityBean.ContentsBean> data;
    private Context context;

    public Travles_ImgRvAdapter(List<TravelsBean.DataBean.ActivityBean.ContentsBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.travels_imgrv,parent,false);
        return new ViewHolder(view);
    }


    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if(data.size()>0){
            Glide.with(context).load(data.get(position).getPhoto_url()).into(holder.iv);
        }
        holder.iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context,"点击",Toast.LENGTH_LONG).show();
            }
        });
    }


    @Override
    public int getItemCount() {
        return data == null?0:data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView iv;
        public ViewHolder(View itemView) {
            super(itemView);
            iv = (ImageView) itemView.findViewById(R.id.imgrv_iv);
        }
    }
}
